/***
 * 请求服务器资源JS
 */

import axios from '../http'

const deliverResponse = response => {
  let r = response.data
  if (r.code === 0) return r.data
  throw new Error(response.message)
}
const throwError = error => {
  throw error
}

const resources = {
  uploadImage(file) {
    let bundle = new FormData()
    bundle.append('file', file)
    return axios.post('/iyx/feedback/UploadImage', bundle)
      .then(deliverResponse, throwError)
  },
  getCourseFeedbackList(start = 0, length = 3) {
    return axios.get('/iyx/feedback/getfeedbacksList', {
      params: {
        start, length
      }
    }).then(deliverResponse, throwError)
  },
  createCourseFeedback(bundle) {
    return axios.post('/iyx/feedback/addfeedback', bundle)
      .then(response => {
        if (response.success) return true
        else return false
      })
  },
  deleteCourseFeedback(id) {
    if (!id) return

    return axios.get('/iyx/feedback/deletefeedback', {params: {id}})
      .then(response => {
        console.log('ddd')
        if (response.success) return true
        else return false
      })
  }
}
export default resources
